//
//  YMNavigationController.m
//  GuoAo
//
//  Created by y s on 2023/3/11.
//

#import "YMNavigationController.h"
#import "YMBaseViewController.h"

@interface YMNavigationController ()

@end

@implementation YMNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton *button = [[UIButton alloc] init];
        [button setImage:[UIImage imageNamed:@"tools_nav_left_back"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"tools_nav_left_back"] forState:UIControlStateHighlighted];
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.frame = CGRectMake([SFitUtil fit:16], 0, 24, 24);
        button.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    }
    if ([viewController isKindOfClass:[YMBaseViewController class]] == NO){
        self.view.backgroundColor = [UIColor whiteColor];
        if (@available(iOS 15.0, *)) {
            UINavigationBarAppearance *navBar = [[UINavigationBarAppearance alloc] init];
            navBar.backgroundColor = [UIColor whiteColor];
            self.navigationBar.scrollEdgeAppearance = navBar;
            self.navigationBar.standardAppearance = navBar;
        } else {
            self.navigationBar.barTintColor = [UIColor whiteColor];
        }
        self.navigationBar.translucent=false;
        [self setNeedsStatusBarAppearanceUpdate];
    }
    
    [super pushViewController:viewController animated:animated];
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    if ([self.topViewController isKindOfClass:[YMBaseViewController class]]){
        YMBaseViewController *vc = (YMBaseViewController *)self.topViewController;
        UIStatusBarStyle style = (vc.isWhiteStatusBar ? UIStatusBarStyleLightContent:UIStatusBarStyleDefault);
        return style;
    }else{
        return UIStatusBarStyleDefault;
    }
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}

@end
